package view;

import controller.ControllerCadastraUsuario;
import java.awt.HeadlessException;
import java.text.ParseException;
import java.util.Date;
import java.util.HashMap;
import java.util.Map;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.swing.JFormattedTextField;
import javax.swing.JOptionPane;
import javax.swing.text.MaskFormatter;
import model.Funcionario;

/**
 *
 * @author Dick developer
 */
public class JCadastroUsuario extends javax.swing.JFrame {

    private ControllerCadastraUsuario ccu;
    private JPrincipal jf;
    private Funcionario funcionario;
    private Date date;
    private int tamanho;
    private int cont = 1;
    private boolean alterar;
    private String cpf;
    private Map<String, Integer> cargo = new HashMap<>();

    public JCadastroUsuario() throws HeadlessException {
    }
    
    
    public JCadastroUsuario(ControllerCadastraUsuario ccu,JPrincipal jf) {        
        initComponents();
        cargo.put("Administrador", 1);
        cargo.put("Caixa", 2);
        cargo.put("Garçom", 3);
        cargo.put("Barmen", 4);
                
        this.ccu = ccu;
        this.jf = jf;
        zera_tela();
    }


    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        jButton1 = new javax.swing.JButton();
        jButton2 = new javax.swing.JButton();
        jLabel9 = new javax.swing.JLabel();
        jLabel3 = new javax.swing.JLabel();
        senha = new javax.swing.JFormattedTextField();
        jLabel13 = new javax.swing.JLabel();
        jLabel4 = new javax.swing.JLabel();
        nome = new javax.swing.JFormattedTextField();
        jLabel7 = new javax.swing.JLabel();
        uf = new javax.swing.JFormattedTextField();
        jLabel10 = new javax.swing.JLabel();
        funcao = new javax.swing.JComboBox();
        telefone = new javax.swing.JFormattedTextField();
        jLabel11 = new javax.swing.JLabel();
        jLabel12 = new javax.swing.JLabel();
        jLabel14 = new javax.swing.JLabel();
        jLabel15 = new javax.swing.JLabel();
        jLabel16 = new javax.swing.JLabel();
        jLabel17 = new javax.swing.JLabel();
        jLabel18 = new javax.swing.JLabel();
        rua = new javax.swing.JFormattedTextField();
        bairro = new javax.swing.JFormattedTextField();
        cidade = new javax.swing.JFormattedTextField();
        rg = new javax.swing.JFormattedTextField();
        login = new javax.swing.JFormattedTextField();
        zera = new javax.swing.JButton();
        editar = new javax.swing.JButton();
        documento = new javax.swing.JFormattedTextField();
        jLabel8 = new javax.swing.JLabel();
        jMenuBar1 = new javax.swing.JMenuBar();
        jMenu1 = new javax.swing.JMenu();
        jMenu2 = new javax.swing.JMenu();
        jMenu3 = new javax.swing.JMenu();

        setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
        setUndecorated(true);
        getContentPane().setLayout(new org.netbeans.lib.awtextra.AbsoluteLayout());

        jButton1.setIcon(new javax.swing.ImageIcon(getClass().getResource("/images/fechar.png"))); // NOI18N
        jButton1.setBorderPainted(false);
        jButton1.setContentAreaFilled(false);
        jButton1.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseEntered(java.awt.event.MouseEvent evt) {
                jButton1MouseEntered(evt);
            }
            public void mouseExited(java.awt.event.MouseEvent evt) {
                jButton1MouseExited(evt);
            }
        });
        jButton1.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton1ActionPerformed(evt);
            }
        });
        getContentPane().add(jButton1, new org.netbeans.lib.awtextra.AbsoluteConstraints(260, 350, 60, 60));

        jButton2.setForeground(new java.awt.Color(255, 255, 255));
        jButton2.setIcon(new javax.swing.ImageIcon(getClass().getResource("/images/ok.png"))); // NOI18N
        jButton2.setBorderPainted(false);
        jButton2.setContentAreaFilled(false);
        jButton2.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                jButton2MouseClicked(evt);
            }
            public void mouseEntered(java.awt.event.MouseEvent evt) {
                jButton2MouseEntered(evt);
            }
            public void mouseExited(java.awt.event.MouseEvent evt) {
                jButton2MouseExited(evt);
            }
        });
        jButton2.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton2ActionPerformed(evt);
            }
        });
        getContentPane().add(jButton2, new org.netbeans.lib.awtextra.AbsoluteConstraints(360, 350, 60, 60));

        jLabel9.setFont(new java.awt.Font("Arial", 1, 18)); // NOI18N
        jLabel9.setText("Cadastro de Usuário");
        getContentPane().add(jLabel9, new org.netbeans.lib.awtextra.AbsoluteConstraints(260, 30, -1, -1));

        jLabel3.setText("Documento:");
        getContentPane().add(jLabel3, new org.netbeans.lib.awtextra.AbsoluteConstraints(50, 120, -1, -1));

        senha.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                senhaActionPerformed(evt);
            }
        });
        getContentPane().add(senha, new org.netbeans.lib.awtextra.AbsoluteConstraints(560, 280, 80, -1));

        jLabel13.setIcon(new javax.swing.ImageIcon(getClass().getResource("/images/cpf.jpg"))); // NOI18N
        getContentPane().add(jLabel13, new org.netbeans.lib.awtextra.AbsoluteConstraints(150, 120, 40, 30));

        jLabel4.setText("Nome:");
        getContentPane().add(jLabel4, new org.netbeans.lib.awtextra.AbsoluteConstraints(50, 160, -1, -1));

        nome.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                nomeActionPerformed(evt);
            }
        });
        getContentPane().add(nome, new org.netbeans.lib.awtextra.AbsoluteConstraints(200, 160, 110, -1));

        jLabel7.setText("Telefone:");
        getContentPane().add(jLabel7, new org.netbeans.lib.awtextra.AbsoluteConstraints(50, 200, -1, -1));

        uf.setColumns(2);
        uf.setMaximumSize(new java.awt.Dimension(2, 2));
        uf.setMinimumSize(new java.awt.Dimension(2, 2));
        uf.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                ufActionPerformed(evt);
            }
        });
        uf.addKeyListener(new java.awt.event.KeyAdapter() {
            public void keyReleased(java.awt.event.KeyEvent evt) {
                ufKeyReleased(evt);
            }
        });
        getContentPane().add(uf, new org.netbeans.lib.awtextra.AbsoluteConstraints(420, 240, 50, -1));

        jLabel10.setText("Senha:");
        getContentPane().add(jLabel10, new org.netbeans.lib.awtextra.AbsoluteConstraints(510, 280, -1, -1));

        funcao.setEditable(true);
        funcao.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "Administrador", "Caixa", "Garçom", "Barmen" }));
        getContentPane().add(funcao, new org.netbeans.lib.awtextra.AbsoluteConstraints(200, 240, 110, -1));

        telefone.setText("");
        telefone.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                telefoneActionPerformed(evt);
            }
        });
        getContentPane().add(telefone, new org.netbeans.lib.awtextra.AbsoluteConstraints(200, 200, 110, -1));

        jLabel11.setText("Função:");
        getContentPane().add(jLabel11, new org.netbeans.lib.awtextra.AbsoluteConstraints(50, 240, -1, -1));

        jLabel12.setText("Endereço:");
        getContentPane().add(jLabel12, new org.netbeans.lib.awtextra.AbsoluteConstraints(360, 120, -1, -1));

        jLabel14.setText("Bairro:");
        getContentPane().add(jLabel14, new org.netbeans.lib.awtextra.AbsoluteConstraints(360, 160, -1, -1));

        jLabel15.setText("Cidade:");
        getContentPane().add(jLabel15, new org.netbeans.lib.awtextra.AbsoluteConstraints(360, 200, -1, -1));

        jLabel16.setText("Estado:");
        getContentPane().add(jLabel16, new org.netbeans.lib.awtextra.AbsoluteConstraints(360, 240, -1, -1));

        jLabel17.setText("CPF: ");
        getContentPane().add(jLabel17, new org.netbeans.lib.awtextra.AbsoluteConstraints(50, 280, -1, -1));

        jLabel18.setText("Login:");
        getContentPane().add(jLabel18, new org.netbeans.lib.awtextra.AbsoluteConstraints(360, 280, -1, -1));

        rua.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                ruaActionPerformed(evt);
            }
        });
        getContentPane().add(rua, new org.netbeans.lib.awtextra.AbsoluteConstraints(420, 120, 220, -1));

        bairro.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                bairroActionPerformed(evt);
            }
        });
        getContentPane().add(bairro, new org.netbeans.lib.awtextra.AbsoluteConstraints(420, 160, 220, -1));

        cidade.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                cidadeActionPerformed(evt);
            }
        });
        getContentPane().add(cidade, new org.netbeans.lib.awtextra.AbsoluteConstraints(420, 200, 220, -1));

        rg.setDocument(new util.CPFField());
        rg.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                rgActionPerformed(evt);
            }
        });
        getContentPane().add(rg, new org.netbeans.lib.awtextra.AbsoluteConstraints(200, 280, 110, -1));

        login.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                loginActionPerformed(evt);
            }
        });
        getContentPane().add(login, new org.netbeans.lib.awtextra.AbsoluteConstraints(420, 280, 80, -1));

        zera.setIcon(new javax.swing.ImageIcon(getClass().getResource("/images/xpequeno.png"))); // NOI18N
        zera.setBorderPainted(false);
        zera.setContentAreaFilled(false);
        zera.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                zeraMouseClicked(evt);
            }
            public void mouseEntered(java.awt.event.MouseEvent evt) {
                zeraMouseEntered(evt);
            }
            public void mouseExited(java.awt.event.MouseEvent evt) {
                zeraMouseExited(evt);
            }
        });
        zera.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                zeraActionPerformed(evt);
            }
        });
        getContentPane().add(zera, new org.netbeans.lib.awtextra.AbsoluteConstraints(320, 110, 30, 30));

        editar.setIcon(new javax.swing.ImageIcon(getClass().getResource("/images/editar1.png"))); // NOI18N
        editar.setBorderPainted(false);
        editar.setContentAreaFilled(false);
        editar.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                editarMouseClicked(evt);
            }
            public void mouseEntered(java.awt.event.MouseEvent evt) {
                editarMouseEntered(evt);
            }
            public void mouseExited(java.awt.event.MouseEvent evt) {
                editarMouseExited(evt);
            }
        });
        editar.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                editarActionPerformed(evt);
            }
        });
        getContentPane().add(editar, new org.netbeans.lib.awtextra.AbsoluteConstraints(320, 150, 30, 30));

        try {
            documento.setFormatterFactory(new javax.swing.text.DefaultFormatterFactory(new javax.swing.text.MaskFormatter("###.###.###-##")));
        } catch (java.text.ParseException ex) {
            ex.printStackTrace();
        }
        documento.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                documentoActionPerformed(evt);
            }
        });
        documento.addKeyListener(new java.awt.event.KeyAdapter() {
            public void keyReleased(java.awt.event.KeyEvent evt) {
                documentoKeyReleased(evt);
            }
        });
        getContentPane().add(documento, new org.netbeans.lib.awtextra.AbsoluteConstraints(200, 120, 110, -1));

        jLabel8.setForeground(new java.awt.Color(255, 255, 255));
        jLabel8.setIcon(new javax.swing.ImageIcon(getClass().getResource("/images/fundotelasinvertido.png"))); // NOI18N
        getContentPane().add(jLabel8, new org.netbeans.lib.awtextra.AbsoluteConstraints(0, 0, 700, 450));

        jMenuBar1.setBackground(java.awt.Color.white);

        jMenu1.setBackground(java.awt.Color.white);
        jMenu1.setText("Ajuda");
        jMenuBar1.add(jMenu1);

        jMenu2.setBackground(java.awt.Color.white);
        jMenu2.setText("Regras da casa");
        jMenuBar1.add(jMenu2);

        jMenu3.setBackground(java.awt.Color.white);
        jMenu3.setText("Sair");
        jMenuBar1.add(jMenu3);

        setJMenuBar(jMenuBar1);

        pack();
        setLocationRelativeTo(null);
    }// </editor-fold>//GEN-END:initComponents

    private void jButton1MouseEntered(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_jButton1MouseEntered

        jButton1.setSize(70,70);

        // TODO add your handling code here:
    }//GEN-LAST:event_jButton1MouseEntered

    private void jButton1MouseExited(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_jButton1MouseExited

        jButton1.setSize(60,60);

        // TODO add your handling code here:
    }//GEN-LAST:event_jButton1MouseExited

    private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton1ActionPerformed
        
        jf.restaurar(jf);
        this.hide();

        
    }//GEN-LAST:event_jButton1ActionPerformed

    private void jButton2MouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_jButton2MouseClicked

        // TODO add your handling code here:
    }//GEN-LAST:event_jButton2MouseClicked

    private void jButton2MouseEntered(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_jButton2MouseEntered

        jButton2.setSize(70,70);
    }//GEN-LAST:event_jButton2MouseEntered

    private void jButton2MouseExited(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_jButton2MouseExited

        jButton2.setSize(60,60);

        // TODO add your handling code here:
    }//GEN-LAST:event_jButton2MouseExited

    private void jButton2ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton2ActionPerformed
        
        if(alterar == false){

        funcionario = new Funcionario();
        funcionario.setCpf(documento.getText().toString());
        funcionario.setRg(rg.getText().toString());
        funcionario.setNome(nome.getText().toString());
        funcionario.setTelefone(telefone.getText().toString());
        funcionario.setObservacao("");
        funcionario.setEndereco(rua.getText().toString());
        funcionario.setBairro(bairro.getText().toString());
        funcionario.setCidade(cidade.getText().toString());
        funcionario.setEstado(uf.getText().toString());
        funcionario.setLogin(login.getText().toString());
        funcionario.setSenha(senha.getText().toString());
        //funcionario.setTipo(cargo.get((String)funcao.getSelectedItem()));
        funcionario.setTipo(funcao.getSelectedIndex() + 1);

            if(ccu.cadastra_funcionario(funcionario)){

                JOptionPane.showMessageDialog(null, "Novo Funcionário cadstrado com sucesso! ");
                zera_tela();

            }
        
        }else if (alterar == true){
            
            //funcionario = new Funcionario();
            //funcionario.setCpf(documento.getText().toString());
            funcionario.setRg(rg.getText().toString());
            funcionario.setNome(nome.getText().toString());
            funcionario.setTelefone(telefone.getText().toString());
            funcionario.setObservacao("");
            funcionario.setEndereco(rua.getText().toString());
            funcionario.setBairro(bairro.getText().toString());
            funcionario.setCidade(cidade.getText().toString());
            funcionario.setEstado(uf.getText().toString());
            funcionario.setLogin(login.getText().toString());
            funcionario.setSenha(senha.getText().toString());
            funcionario.setTipo(funcao.getSelectedIndex() + 1);

            if(ccu.altera_funcionario(funcionario)){

                JOptionPane.showMessageDialog(null, "Funcionário alterado com sucesso ! ");
                zera_tela();
                    
            }

        }
        
        
        
    }//GEN-LAST:event_jButton2ActionPerformed

    private void senhaActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_senhaActionPerformed

    }//GEN-LAST:event_senhaActionPerformed

    private void ufActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_ufActionPerformed
        // TODO add your handling code here:
    }//GEN-LAST:event_ufActionPerformed

    private void nomeActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_nomeActionPerformed
        // TODO add your handling code here:
    }//GEN-LAST:event_nomeActionPerformed

    private void telefoneActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_telefoneActionPerformed
        // TODO add your handling code here:
    }//GEN-LAST:event_telefoneActionPerformed

    private void ruaActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_ruaActionPerformed
        // TODO add your handling code here:
    }//GEN-LAST:event_ruaActionPerformed

    private void bairroActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_bairroActionPerformed
        // TODO add your handling code here:
    }//GEN-LAST:event_bairroActionPerformed

    private void cidadeActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_cidadeActionPerformed
        // TODO add your handling code here:
    }//GEN-LAST:event_cidadeActionPerformed

    private void rgActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_rgActionPerformed
        // TODO add your handling code here:
    }//GEN-LAST:event_rgActionPerformed

    private void loginActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_loginActionPerformed
        // TODO add your handling code here:
    }//GEN-LAST:event_loginActionPerformed

    private void zeraMouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_zeraMouseClicked
        // TODO add your handling code here:
    }//GEN-LAST:event_zeraMouseClicked

    private void zeraMouseEntered(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_zeraMouseEntered
        zera.setSize(40,40);
    }//GEN-LAST:event_zeraMouseEntered

    private void zeraMouseExited(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_zeraMouseExited
        zera.setSize(30,30);
    }//GEN-LAST:event_zeraMouseExited

    private void zeraActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_zeraActionPerformed
        zera_tela();
    }//GEN-LAST:event_zeraActionPerformed

    private void editarMouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_editarMouseClicked

        liberaCampo();
        
        
    }//GEN-LAST:event_editarMouseClicked

    private void editarMouseEntered(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_editarMouseEntered

        editar.setSize(40,40);

    }//GEN-LAST:event_editarMouseEntered

    private void editarMouseExited(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_editarMouseExited

        editar.setSize(30,30);

    }//GEN-LAST:event_editarMouseExited

    private void editarActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_editarActionPerformed
        
    }//GEN-LAST:event_editarActionPerformed

    private void documentoActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_documentoActionPerformed
        // TODO add your handling code here:
    }//GEN-LAST:event_documentoActionPerformed

    private void documentoKeyReleased(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_documentoKeyReleased
        
        //ccu = new ControllerCadastraUsuario();
        
        if(documento.getText().length() == 4){
            cont =1;
        }
        
        while(cont ==1){
            tamanho = documento.getText().length();
            tamanho = (tamanho-11);
            cont = 2;
        }
        tamanho = (tamanho +1);
        
        //JOptionPane.showMessageDialog(null, tamanho);
        
        if(tamanho >= 14){

            cpf = documento.getText();
            
            if(ccu.verifica_se_funcionario_tem_cadastro(cpf)){
                
                // usuario ja cadastrado 
                JOptionPane.showMessageDialog(null, "Este usuario já esta cadastrado no sistema");
                
                funcionario = new Funcionario();
                funcionario = ccu.retorna_dados_do_funcionario(cpf);
                documento.setText(funcionario.getCpf());
                nome.setText(funcionario.getNome());
                telefone.setText(funcionario.getTelefone());
                funcao.setSelectedIndex(funcionario.getTipo() -1 );
                
                rg.setText(funcionario.getRg());
                rua.setText(funcionario.getEndereco());
                bairro.setText(funcionario.getBairro());
                cidade.setText(funcionario.getCidade());
                uf.setText(funcionario.getEstado());
                login.setText(funcionario.getLogin());
                senha.setText(funcionario.getSenha());
                
                bloqueiaCampo();
                libera_editar();
                
            }else{
                
                //JOptionPane.showMessageDialog(null, "Esse unuario n existe ");
                //zera_tela();
                liberaCampo();
                //JOptionPane.showMessageDialog(null, "Este usuario não tem cadastro ativo no sistema");
                
            }
        
        }

        
    }//GEN-LAST:event_documentoKeyReleased

    private void ufKeyReleased(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_ufKeyReleased
       
        if(uf.getText().length() > 2){  
            JOptionPane.showMessageDialog(null, "Campo UF do Estado excedeu o tamanho permitido (2 caracteres)");

                uf.setText("");
        }  
        
    }//GEN-LAST:event_ufKeyReleased

    /**
     * @param args the command line arguments
     */

    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JFormattedTextField bairro;
    private javax.swing.JFormattedTextField cidade;
    private javax.swing.JFormattedTextField documento;
    private javax.swing.JButton editar;
    private javax.swing.JComboBox funcao;
    private javax.swing.JButton jButton1;
    private javax.swing.JButton jButton2;
    private javax.swing.JLabel jLabel10;
    private javax.swing.JLabel jLabel11;
    private javax.swing.JLabel jLabel12;
    private javax.swing.JLabel jLabel13;
    private javax.swing.JLabel jLabel14;
    private javax.swing.JLabel jLabel15;
    private javax.swing.JLabel jLabel16;
    private javax.swing.JLabel jLabel17;
    private javax.swing.JLabel jLabel18;
    private javax.swing.JLabel jLabel3;
    private javax.swing.JLabel jLabel4;
    private javax.swing.JLabel jLabel7;
    private javax.swing.JLabel jLabel8;
    private javax.swing.JLabel jLabel9;
    private javax.swing.JMenu jMenu1;
    private javax.swing.JMenu jMenu2;
    private javax.swing.JMenu jMenu3;
    private javax.swing.JMenuBar jMenuBar1;
    private javax.swing.JFormattedTextField login;
    private javax.swing.JFormattedTextField nome;
    private javax.swing.JFormattedTextField rg;
    private javax.swing.JFormattedTextField rua;
    private javax.swing.JFormattedTextField senha;
    private javax.swing.JFormattedTextField telefone;
    private javax.swing.JFormattedTextField uf;
    private javax.swing.JButton zera;
    // End of variables declaration//GEN-END:variables

    
public void exibe() {
    setVisible(true);     
}

    private void bloqueiaCampo() {
        senha.setEnabled(false);
        nome.setEnabled(false);
        telefone.setEnabled(false);
        uf.setEnabled(false);
        //sexo.setEnabled(false);
        funcao.setEnabled(false);
        rua.setEnabled(false);
        bairro.setEnabled(false);
        cidade.setEnabled(false);
        uf.setEnabled(false);
        rg.setEnabled(false);
        login.setEnabled(false);
        senha.setEnabled(false);
        //nascimento.setEnabled(false);
        
        
    }

    private void liberaCampo() {
        senha.setEnabled(true);
        nome.setEnabled(true);
        telefone.setEnabled(true);
        uf.setEnabled(true);
        //sexo.setEnabled(true);
        funcao.setEnabled(true);
        rua.setEnabled(true);
        bairro.setEnabled(true);
        cidade.setEnabled(true);
        uf.setEnabled(true);
        rg.setEnabled(true);
        login.setEnabled(true);
        senha.setEnabled(true);
        documento.setEnabled(false);
        //nascimento.setEnabled(true);
    }

    private void libera_editar(){
        
        editar.setVisible(true);
        
        alterar = true;
        
    }
    private void blokeia_editar(){
        
        editar.setVisible(false);
        alterar = false;
        
    }

    private void zera_tela(){
    
        bloqueiaCampo();
        blokeia_editar();
        cont =1;
        documento.setText("");
        senha.setText("");
        nome.setText("");
        telefone.setText("");
        uf.setText("");
        //sexo.setSelectedItem("M");
        funcao.setSelectedIndex(0);
        rua.setText("");
        bairro.setText("");
        cidade.setText("");
        uf.setText("");
        rg.setText("");
        login.setText("");
        documento.setEnabled(true);
        //nascimento.setText("");
        
    }

}
